
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>修改部门</title>
<link rel="stylesheet" type="text/css" 
      href="../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" 
      href="../themes/icon.css">
<link rel="stylesheet" type="text/css" 
      href="../themes/color.css">
<link rel="stylesheet" type="text/css" 
      href="../demo/demo.css">
<script type="text/javascript" 
      src="../bootstrap/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" 
      src="../js/jquery.easyui.min.js"></script>
<script type="text/javascript" 
      src="../js/easyui-lang-zh_CN.js"></script>

</head>
 <script type="text/javascript">
        var url;
        function addDepartment(){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','New User');
            $('#fm').form('clear');
            url = '../add';
        }
        function updateDepartment(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','Edit User');
                $('#fm').form('load',row);
                url = '../update?id='+row.id;
            }
        }
        function saveUser(){
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.errorMsg){
                        $.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
                    }
                }
            });
        }
        function deleteDepartment(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('警告','你想删除这部门吗?',function(r){
                    if (r){
                    	
                        $.post('../delete',row,function(result){
                        	
                                $('#dg').datagrid('reload');    // reload the user data
                                
                        },'json');
                    }
                });
            }
        }

    </script>
<body>
    <table id="dg" title="部门管理" class="easyui-datagrid" style="width:700px;height:250px"
            url="../select"
            toolbar="#toolbar" pagination="true"
            rownumbers="true" fitColumns="true" singleSelect="true" pageNumber="1" pageSize="5" pageList="[5,10,15,20]">
        <thead>
            <tr>
                <th field="deptId" width="50" hidden="true">部门id</th>
                <th field="deptName" width="50">部门名字</th>
                <th field="manager" width="50">部门经理</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addDepartment()">增加部门</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="updateDepartment()">修改部门</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteDepartment()">删除部门</a>
    </div>
    <div id="dlg" class="easyui-dialog" style="width:400px"
            closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc">部门信息</div>
            <div style="margin-bottom:10px;visibility: hidden;">
                <input name="deptId" class="easyui-textbox"  label="部门id" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="deptName" class="easyui-textbox" required="true" label="部门名字" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="manager" class="easyui-textbox" required="true" label="部门经理" style="width:100%">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
    </div>
   
</body>
</html>